package com.neusoft.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.CommonResult;
import com.neusoft.po.User;
import com.neusoft.service.LoginService;

//@CrossOrigin("*")   //跨域处理
@RefreshScope
@RestController
@RequestMapping("/LoginController")
public class LoginController {
	@Autowired
	LoginService loginService;
	
//	@RequestMapping("/saveUser")
	@PostMapping("/saveUser/{userid}/{password}/{username}/{usersex}")
	public CommonResult<Integer> saveUser(@PathVariable("userid") String userid,
			@PathVariable("password") String password,
			@PathVariable("username") String username,
			@PathVariable("usersex") int usersex)
	{
		User user=new User(userid,password,username,usersex);
		int result=loginService.saveUser(user);
		return new CommonResult<Integer>(200,"success",result);
	}
	
//	@RequestMapping("/getUserByIdByPass")
	@GetMapping("/getUserByIdByPass/{userId}/{password}")
	public CommonResult<User> getUserByIdByPass(@PathVariable("userId") String username,@PathVariable("password") String password)
	{
		User user=new User();
		user.setUserId(username);
		user.setPassword(password);
		User user2=loginService.getUserByIdByPass(user);
		return new CommonResult<User>(200,"success",user2);
	}

//	@RequestMapping("/getUserById")
	@GetMapping("/getUserById/{userId}")
	public CommonResult<Integer> getUserById(@PathVariable("userId") String userId) throws Exception{
	    int result = loginService.getUserById(userId);
	    return new CommonResult<Integer>(200,"success",result);

	  }
}
